package com.ruoyi.common.exception;

import com.ruoyi.common.core.domain.AjaxResult;

/**
 * 业务异常
 */
public class BusinessException extends RuntimeException {
    private static final long serialVersionUID = 1L;
    
    /**
     * 错误码
     */
    private final Integer code;
    
    /**
     * 错误提示
     */
    private final String message;
    
    public BusinessException(String message) {
        this(500, message);
    }
    
    public BusinessException(String message, Throwable cause) {
        super(message, cause);
        this.code = 500;
        this.message = message;
    }
    
    public BusinessException(Integer code, String message) {
        this.code = code;
        this.message = message;
    }
    
    public Integer getCode() {
        return code;
    }
    
    @Override
    public String getMessage() {
        return message;
    }
    
    /**
     * 转换为标准响应格式
     */
    public AjaxResult toAjaxResult() {
        return AjaxResult.error(code, message);
    }
}